<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1.解决异步操作中的回调地狱问题
    /*   function one() {
        setTimeout(() => {
          console.log(111);
          iterator.next()
        }, 1000);
      }

      function two() {
        setTimeout(() => {
          console.log(111);
          iterator.next()
        }, 2000);
      }

      function three() {
        setTimeout(() => {
          console.log(111);
          iterator.next()
        }, 3000);
      }

      function* gen() {
        yield one()
        yield two()
        yield three()
      }
      let iterator = gen()
      iterator.next() */
    // 2. Case2
    function one() {
      setTimeout(() => {
        let data = '用户数据'
        // 调用next方法，并且将数据传入
        // 这是第二次调用next  他的实参返回的是第一个yield的结果
        iterator.next(data)
      }, 1000);
    }

    function two() {
      setTimeout(() => {
        let data = '订单信息'
        iterator.next(data)
      }, 1000);
    }

    function three() {
      setTimeout(() => {
        let data = '完成支付'
        iterator.next(data)
      }, 1000);
    }

    function* gen() {
      let users = yield one()
      console.log(users);
      let order = yield two()
      console.log(order);
      let pay = yield three()
      console.log(pay);
    }
    let iterator = gen()
    iterator.next()
  </script>
</body>

</html>